<template>
  <div id="app">
    <TopBar :key="topbarKey" />
    <Header />
    <router-view @updataTopBarKey="updateKeyFn" />
    <Footer />
    <Login v-show="isShowLoginModel" />
    <transition name="slide">
      <Toast v-show="isShowToast" />
    </transition>
  </div>
</template>
<script>
import TopBar from "@/components/TopBar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import { JingpinAPI,UserProfilesAPI } from "@/request/api";
import Login from "@/components/Login.vue";
import { mapState } from "vuex";
import Toast from "@/components/Toast.vue";
export default {
  components: {
    Footer,
    Header,
    TopBar,
    Login,
    Toast,
  },
  data(){
    return{
      topbarKey:0
    }
  },
  computed: {
    ...mapState({
      isShowLoginModel: (state) => state.LoginModel.isShowLoginModel,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  methods:{
    updateKeyFn(){
   this.topbarKey++
    }
  },
  async created() {
    let res = await JingpinAPI();
    console.log("res3:", res);

    //暂时测试获取用户信息
    let user = await UserProfilesAPI();
    console.log("用户信息：", user);
  },
   watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        //当路由地址发生变化时,让topbar重载(重新加载)
        if (newVal != oldVal) {
          this.topbarKey++;
        }
      },
    },
  },
};
</script>

<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
